package cn.wl.pchart.service.impl;

import cn.wl.pchart.dao.CommunicationMapper;
import cn.wl.pchart.dao.UserMapper;
import cn.wl.pchart.entity.Message;
import cn.wl.pchart.service.CommunicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

// 聊天信息服务实现
@Service("CommunicationService")
public class CommunicationServiceImpl implements CommunicationService {

    @Autowired
    CommunicationMapper communicationMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<Message> getMessage(String user1, String user2, String time, Integer num) {
        List<Message> messages = communicationMapper.getMessage(user1, user2, time, num);
        for (Message i : messages)
        {
            i.setImg(userMapper.getImage(i.getFrom()));
        }
        return messages;
    }

    @Override
    public void saveMessage(String from, String to, String data) {
        communicationMapper.saveMessage(from, to, data);
    }

    @Override
    public void deleteMessage(String mid) {
        communicationMapper.deleteMessage(mid);
    }
}
